<template>
  <el-row class="home" :gutter="20">
    <el-col :span="8" style="margin-top: 20px">
      <el-card shadow="hover">
        <div class="user">
          <img src="../../assets/avatar.jpg" />
          <div class="user-info">
            <p class="name">Admin</p>
            <p class="role">超级管理员</p>
          </div>
        </div>
        <div class="login-info">
          <p>上次登录时间:<span>2022-7-11</span></p>
          <p>上次登录地点:<span>南京</span></p>
        </div>
      </el-card>
      <el-card shadow="hover" style="margin-top: 20px" height="450px">
        <el-table :data="tableData">
          <el-table-column
            v-for="(val, key) in tableLabel"
            :key="key"
            :prop="key"
            :label="val"
          >
          </el-table-column>
        </el-table>
      </el-card>
    </el-col>
    <el-col :span="16" style="margin-top: 20px">
      <div class="num ">
        <el-card
          :body-style="{ display: flex, padding: 0 }"
          v-for="item in countData"
          :key="item.name"
        >
          <component
            class="icons"
            :is="item.icon"
            :style="{ background: item.color }"
          ></component>
          <div class="detail">
            <p class='num'>Y{{item.value}}</p>
            <p class='txt'>{{item.name}}</p>
          </div>
        </el-card>
      </div>
      <el-card style="height:200px">
        <div ref='echart' style="height:280px">

        </div>
      </el-card>
    </el-col>
  </el-row>
</template>
<script>
import { defineComponent, getCurrentInstance, onMounted, reactive, ref } from "vue";
import axios from "axios";
export default defineComponent({
  setup() {
    const {proxy}=getCurrentInstance()
    let tableData = ref([]);
    let countData=ref([])
    let tableLabel = {
      name: "手机类型",
      todayBuy: "今日购买",
      mothBuy: "本月购买",
      totalBuy: "总购买"
    };
    const getTablList = async () => {
      ///home/getData 本地模拟 fastmoack
      // await axios
      //   .get(
      //     "https://www.fastmock.site/mock/499dba58cacc189aa0759409358d3823/api/home/getData"
      //   )
      //   .then((res) => {
      //     //改变值不能直接赋值 要借助ref
      //     if(res.data.code==200){
      //         tableData.value = res.data.data.tableData;
      //     }
      //   });
      console.log(proxy,'proxy')
    let res= await proxy.$api.getTableData()
     tableData.value = res.tableData
    console.log(res,'res ')
    };
    //获取首页count数据
    const getCountData=async ()=>{
      let res=await proxy.$api.getCountData()
     countData.value = res

    }
    onMounted(() => {
      getTablList();
      getCountData()
    });

    //关于echarts表格渲染部分
    let xOptions=reactive( )
    return { tableData, tableLabel ,countData};
  }
});
</script>

<style lang="less" scoped>
.home {
  .user {
    display: flex;
    align-items: center;
    padding-bottom: 20px;
    border-bottom: 1px solid #ccc;
    margin-bottom: 20px;
    img {
      width: 150px;
      height: 150px;
      border-radius: 50%;
      margin-right: 40px;
    }
  }
  .login-info {
    p {
      line-height: 30px;
      font-size: 14px;
      color: #999;
      span {
        color: #666;
        margin-left: 60px;
      }
    }
  }
  .num{
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    .el-card{
      width:32%;
      margin-bottom: 20px;
    }
    .icons{
      width:80px;
      height: 80px;
      font-size: 30px;
      text-align: center;
      line-height: 80px;
      color:#fff
    }
    .detail{
      margin-left:15px;
      display: flex;
      flex-direction: column;
      justify-content: center;
      .num{
        font-size: 30px;
        margin-bottom: 10px;
      }
      .txt{
        font-size: 14px;
        color: #ccc;
      }
    }
  }
}
</style>
